/*
 * $Id: ActFileTransferDetails.java,v 1.16 2012/01/18 15:21:46 navdeep_mahajan Exp $
 *
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 *
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */

package com.ge.healthcare.autosc.common.database.pojo;

import java.io.File;

import com.ge.healthcare.autosc.common.database.dao.IFileTransferDetailsDAO;
import com.ge.healthcare.autosc.common.util.TimeFormatStandard;

/**
 * ActFileTransferDetails entity. @author MyEclipse Persistence Tools
 */
public class ActFileTransferDetails extends AbstractFileTransferDetails
		implements java.io.Serializable {

	/**
	 * Eclipse generated
	 */
	private static final long serialVersionUID = 6973773851812677294L;
	public static final String TABLE_NAME = "com.ge.healthcare.autosc.common.database.pojo.ActFileTransferDetails";
	public static final String COL_FT_ID = "ftId";
	public static final String COL_REQUEST_ID = "requestId";
	public static final String COL_IS_INTERNAL = "isInternal";
	public static final String COL_DIRECTION = "direction";
	public static final String COL_STATUS = "status";
	public static final String COL_FILE_NAME = "fileName";

	public static Character INTERNAL = Character.valueOf('Y');
	public static Character EXTERNAL = Character.valueOf('N');
	public static String HIDDEN_FILE = "HIDDEN";

	// Constructors

	/** default constructor */
	public ActFileTransferDetails() {
	}

	public ActFileTransferDetails(ActFileTransferDetails fileInfo, String dir,
			String file) {
		// Constructor is designed for an extracted file. Because of this not
		// all values are being copied.
		super.setFtId(fileInfo.getFtId());
		super.setRequestId(fileInfo.getRequestId());
		super.setFileDir(dir);
		super.setFileName(file);
		super.setStartTime(fileInfo.getStartTime());
		super.setStartTime(fileInfo.getEndTime());
	}

	public void setShemDirection() {
		super.setDirection(IFileTransferDetailsDAO.SHEM_FROM_DEVICE);
	}

	public void setGetDirection() {
		super.setDirection(IFileTransferDetailsDAO.UPLOAD_FROM_DEVICE);
	}

	public void setCompleted() {
		super.setStatus(IFileTransferDetailsDAO.COMPLETED);
	}

	public void setFail() {
		super.setStatus(IFileTransferDetailsDAO.FAILED);
	}

	public boolean isFailed() {
		return (super.getStatus().equals(IFileTransferDetailsDAO.FAILED) ? true
				: false);
	}

	public File getFile() {
		return new File(this.getFileDir(), this.getFileName());
	}

	public String toString() {
		StringBuffer definition = new StringBuffer();
		definition.append("{File Transfer ID=").append(this.getFtId()).append(
				"},");
		definition.append("{Request Id=").append(this.getRequestId()).append(
				"},");
		definition.append("{File Name=").append(this.getFileName())
				.append("},");
		definition.append("{File Directory Location=")
				.append(this.getFileDir()).append("},");
		definition.append("{Status=").append(this.getStatus()).append("},");
		definition.append("{Is Internal=").append(this.isInternalCommFile())
				.append("},");
		definition.append("{Is Internal Value=").append(this.getIsInternal())
				.append("},");
		definition.append("{Content Size=").append(this.getContentSize())
				.append("},");
		definition.append("{Check Sum=").append(this.getCheckSum())
				.append("},");
		definition.append("{Start Time=").append(
				TimeFormatStandard.getDtInEndUserDisplayFormat(this
						.getStartTime())).append("},");
		definition.append("{End Time=").append(
				TimeFormatStandard.getDtInEndUserDisplayFormat(this
						.getEndTime())).append("}");
		definition.append("{Direction=").append(this.getDirection()).append("}");
		return definition.toString();
	}

	/**
	 * @return the isInternalCommFile
	 */
	public boolean isInternalCommFile() {
		if (EXTERNAL.equals(this.getIsInternal())) {
			return false;
		}
		return true;
	}

	/**
	 * @param isInternalCommFile
	 *            the isInternalCommFile to set
	 */
	public void setInternalCommFile(boolean isInternalCommFile) {
		if (isInternalCommFile) {
			this.setIsInternal(INTERNAL);
		} else {
			this.setIsInternal(EXTERNAL);
		}
	}

	public String fileExt() {
		int dotPos = this.getFileName().lastIndexOf(".");
		if (dotPos > -1) {
			int secondPos = this.getFileName().substring(0, dotPos)
					.lastIndexOf(".");
			if (secondPos > -1) {
				return this.getFileName().substring(secondPos);
			} else {
				return this.getFileName().substring(dotPos);
			}
		}
		return "";
	}
}
